﻿using BCCommon;
using BCDto.CRM.BigCustomerDriver;
using BCService.TMS.BigCustomerDriver;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.CRM.BigCustomerDriver
{


    /// <summary>
    /// 大客户专属司机接口
    /// </summary> 
    [ApiExplorerSettings(GroupName = "CRMAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class BigCustomerDriverController : ManagementBaseController
    {
        #region var
        private IBigCustomerDriverService bigCustomerDriverService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public BigCustomerDriverController(IBigCustomerDriverService bigCustomerDriverService)
        {
            this.bigCustomerDriverService = bigCustomerDriverService;
        }
        #endregion

        #region POST 添加  
        /// <summary>
        /// 添加新大客户专属司机纪录
        /// </summary>
        /// <param name="dto">大客户专属司机数据模型</param>
        /// <returns></returns>
        [Log("添加新大客户专属司机纪录")]
        [HttpPost]
        [ProducesResponseType(typeof(BigCustomerDriverRequestDto), 200)]
        public IActionResult Post([FromBody] BigCustomerDriverRequestDto dto)
        {
            var a = bigCustomerDriverService.Add(dto, this.Admin);
            return Ok(a);
        }

        #endregion

        #region POST 批量添加  
        /// <summary>
        /// 添加新大客户专属司机纪录
        /// </summary>
        /// <param name="dtoList">大客户专属司机数据模型列表</param>
        /// <returns></returns>
        [Log("添加新大客户专属司机纪录")] 
        [HttpPost("[action]")] 
        public IActionResult AddList([FromBody] List<BigCustomerDriverRequestDto> dtoList)
        {
            bigCustomerDriverService.AddList(dtoList, this.Admin);
            return NoContent();
        }

        #endregion



        #region 删除  
        /// <summary>
        /// 删除大客户专属司机纪录
        /// </summary>
        /// <param name="bigCustomerDriverId">大客户专属司机ID</param>
        /// <returns></returns>
        [Log("删除大客户专属司机纪录")]
        [HttpDelete("{big_customer_driver_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "big_customer_driver_id")] long bigCustomerDriverId)
        {
            bigCustomerDriverService.Delete(bigCustomerDriverId);
            return NoContent();
        }
        #endregion

        #region GetByID     
        /// <summary>
        /// 获取一条大客户专属司机纪录
        /// </summary>
        /// <param name="bigCustomerDriverId">大客户专属司机ID</param>
        /// <returns></returns>
        [HttpGet("{big_customer_driver_id}")]
        [ProducesResponseType(typeof(BigCustomerDriverDto), 200)]
        public IActionResult Get([FromRoute(Name = "big_customer_driver_id")] long bigCustomerDriverId)
        {
            return (Ok(bigCustomerDriverService.GetById(bigCustomerDriverId)));

        }
        #endregion

        #region Query 
        /// <summary>
        /// 查询大客户专属司机
        /// </summary>
        /// <param name="bigCustomerId">大客户Id</param>
        /// <param name="driverName">司机姓名</param>
        /// <param name="driverPhone">司机电话</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页记录数</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<BigCustomerDriverDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "big_customer_id")] long? bigCustomerId,
            [FromQuery(Name = "driver_name")] string driverName,
            [FromQuery(Name = "driver_phone")] string driverPhone,
            [FromQuery(Name = "index")] int? pageIndex = 1, 
            [FromQuery(Name = "size")] int? pageSize = 10)
        {
            var a = Ok(bigCustomerDriverService.GetList(this.Admin,bigCustomerId,driverName,driverPhone,pageIndex.Value, pageSize.Value));
            return a;
        }
        #endregion 

        #region GetOnlyList
        /// <summary>
        /// 获取大客户专属司机列表
        /// </summary>
        /// <param name="bigCustomerId">大客户Id</param>
        /// <returns></returns>
        [HttpGet("[action]/{big_customer_id}")]
        [ProducesResponseType(typeof(List<BigCustomerDriverDto>), 200)]
        public IActionResult GetOnlyList([FromRoute(Name = "big_customer_id")] long? bigCustomerId)
        {
            return Ok(bigCustomerDriverService.GetOnlyList(this.Admin, bigCustomerId)); 
        }

        #endregion
    }

}
